﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

namespace MVAScratchPad.Views
{
    public sealed partial class Splash : Page
    {
        public Splash()
        {
            this.InitializeComponent();
        }

        #region boilerplate

        public Windows.ApplicationModel.Activation.SplashScreen SplashScreen { get; set; }
        public Action Navigate { get; set; }
        public async void Start()
        {
            // display splash when ready
            MyImage.ImageOpened += (s, e) => Window.Current.Activate();

            // setup size
            Resize();
            Window.Current.SizeChanged += (s, e) => Resize();

            // start
            Window.Current.Activate();
            await LoadThings();
            this.Navigate.Invoke();
        }

        private void Resize()
        {
            MyImage.Height = this.SplashScreen.ImageLocation.Height;
            MyImage.Width = this.SplashScreen.ImageLocation.Width;
            MyImage.SetValue(Canvas.TopProperty, this.SplashScreen.ImageLocation.Top);
            MyImage.SetValue(Canvas.LeftProperty, this.SplashScreen.ImageLocation.Left);
        }

        #endregion

        private async Task LoadThings()
        {
            // TODO
            await Task.Delay(2000);
        }
    }
}
